package com.ruoyi.web.controller.system;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AdvertisingManagement;
import com.ruoyi.system.service.IAdvertisingManagementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 广告管理信息Controller
 *
 * @author ruoyi
 * @date 2024-12-12
 */
@CrossOrigin
@RestController
@RequestMapping("/system/management")
@Api(tags = "广告管理信息相关接口")
public class AdvertisingManagementController extends BaseController {
    @Autowired
    private IAdvertisingManagementService advertisingManagementService;

    /**
     * 查询广告管理信息列表
     */
    @GetMapping("/list")
    @ApiOperation("查询广告管理信息列表   带分页")
    public TableDataInfo list(AdvertisingManagement advertisingManagement) {
        startPage();
        List<AdvertisingManagement> list = advertisingManagementService.selectAdvertisingManagementList(advertisingManagement);
        return getDataTable(list);
    }

    /**
     *增加广告点击次数
     */
    @GetMapping("/clicksByOne")
    @ApiOperation("  增加广告点击次数   ")
    public Object clicksByOne(@RequestParam("id") Integer id) {
          advertisingManagementService.clicksByOne(id);
        return success("增加成功");
    }


    /**
     * 导出广告管理信息列表
     */
    @Log(title = "广告管理信息", businessType = BusinessType.EXPORT)
    @ApiOperation("导出广告管理信息列表   Excel")
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdvertisingManagement advertisingManagement) {
        List<AdvertisingManagement> list = advertisingManagementService.selectAdvertisingManagementList(advertisingManagement);
        ExcelUtil<AdvertisingManagement> util = new ExcelUtil<AdvertisingManagement>(AdvertisingManagement.class);
        util.exportExcel(response, list, "广告管理信息数据");
    }

    /**
     * 获取广告管理信息详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("根据ID 获取广告管理信息详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(advertisingManagementService.selectAdvertisingManagementById(id));
    }

    /**
     * 新增广告管理信息
     */
    @Log(title = "广告管理信息", businessType = BusinessType.INSERT)
    @ApiOperation("新增  广告信息")
    @PostMapping("saveManagement")
    public Object saveManagement( AdvertisingManagement advertisingManagement) throws IOException {
        if (advertisingManagement == null){
            return error("参数不能为空 ！");
        }
        return advertisingManagementService.insertAdvertisingManagement(advertisingManagement);
    }

    /**
     * 修改广告管理信息
     */
    @Log(title = "广告管理信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改  广告信息")
    public Object edit(@RequestBody AdvertisingManagement advertisingManagement) {
        return toAjax(advertisingManagementService.updateAdvertisingManagement(advertisingManagement));
    }

    //获取为指定页面配置的广告信息集合
    @Log(title = "获取为指定页面配置的广告信息集合", businessType = BusinessType.UPDATE)
    @GetMapping("getAdvertisingListByClass")
    @ApiOperation("获取 为指定页面 配置的广告信息集合")
    public Object getAdvertisingListByClass(@RequestParam("className") String className) {
        List<AdvertisingManagement> list = advertisingManagementService.list(new QueryWrapper<AdvertisingManagement>().eq("class_name", className));
        return success(list);
    }



    /**
     * 删除广告管理信息
     */
    @Log(title = "广告管理信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除广告管理信息")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(advertisingManagementService.deleteAdvertisingManagementByIds(ids));
    }
}
